def isodd(x):
    return x % 2 ==1

# 通过返回值是true或者false来返回
ret = filter(isodd,[1,2,3,4,5])
list1 = list(ret)
print(ret)
print(list1)

# 去除空串
def not_empty(s):
    return bool(s and s.strip())
ret2 = filter(not_empty,["a","   a    b      ","","\tssss"])
list2 = list(ret2)
print(list2)

def _odd_iter():
    n = 1
    while True:
        n  = n+2
        yield n

def _not_divisable(n):
    return lambda x : x % n > 0 # 为true则说明不能被整除
def primes():
    yield 2
    it = _odd_iter();
    while True:
        n = next(it)
        yield n
        it = filter(_not_divisable(n),it)
for n in primes():
    if n < 100:
        print(n)
    else:
        break
print("=================================practice1===============================")
# def is_palindrome(n):
#     s = str(n)
#     if len(s) == 1:
#         return True
#     i = 0
#     j = len(s)-1
#     while(i<=j):
#         if(s[i]==s[j]):
#             i+=1
#             j-=1
#         else:
#             return False
#     if(s[i]==s[j]): return True
#     else: return False
def is_palindrome(n):
    return str(n) == str(n)[::-1] # [::-1]是将字符串反转


# 测试:
output = filter(is_palindrome, range(1, 1000))
print('1~1000:', list(output))
if list(filter(is_palindrome, range(1, 200))) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191]:
    print('测试成功!')
else:
    print('测试失败!')
